// pages/my/wallet/wallet.js
let util = require('../../../utils/index')
import http from '../../../services/http/index'
import { ListData,PlainData } from '../../../utils/Data'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    info:{},
    log:{
      data:[],
      hasMore:true,
      page:1
    },
    height:''
  },

  //获取钱包信息
  getInfo(){
    //获取钱包金额
    http.myAccount()
        .then(data => {
          this.setData({
            'info': Object.assign(new PlainData(), {data:data}).data
          });
        });
  },
  //获取账户明细
  getAccountLog(){
    if(!this.data.log.hasMore)return false;
    var param = {
      page:this.data.log.page
    };
    wx.showToast({ //期间为了显示效果可以添加一个过度的弹出框提示“加载中”
      title: 'loading',
      icon: 'loading',
        duration: 10000,
        mask:true
    });
    http.myAccountLog(param)
        .then(data => {
          wx.hideToast();
          if(data.length ==0){
            //没有数据
            this.setData({
              'log':Object.assign(new ListData(),{data:[], hasMore:false,page:param.page})
            });
            return false;
          }

          var hasMore = false,page=param.page;
          if(data.next_page){
            //有下一页
            hasMore = true;
            page++;
          }else{
            hasMore = false
          };
          var logData = this.data.log.data;
          logData = logData.concat(data.list);
          this.setData({
            'log': Object.assign(new ListData(), {data:logData,hasMore:hasMore,page:page})
          });
        });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getInfo();
    this.getAccountLog();
    wx.getSystemInfo({
      success: (res) => {
        this.setData({
          height: res.windowHeight
        });
      }
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    wx.setNavigationBarTitle({
      title: '我的钱包'
    })
  },
  onReachBottom:function(){
    this.getAccountLog();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  


})